<style>
	#neighborhoods_id { float: left; width: 500px; }
	#neighborhoods_id span, #neighborhoods_id div { float: left; }
	#neighborhoods_id ul { float: left; width: 500px; background: #F4F4F4; }
	#neighborhoods_id ul li { float: left; width: 160px; padding: 2px; line-height: 25px; }
	#neighborhoods_id .clr { clear: both; }
	#neighborhoods_id span.n-tab { padding: 3px 10px; margin-right: 1px; background: #1881B4; color: #FFF; cursor: pointer; }
	#neighborhoods_id span.n-tab-active,
	#neighborhoods_id span.n-tab:hover { background: #37befc; color: #3a4549; }
	.tab-container { background: #F4F4F4; width: 500px; border-bottom: 5px solid #FFF; }
</style>

<script type="text/javascript">
<!--
window.addEvent('domready', function(){
	$$('.n-tab').addEvent('click', function(){
		var rel = this.get('rel');

		// hide all cotent 
		$$('.ul-content').set('styles', {'display': 'none'});

		// remove class active 
		$$('.n-tab').removeClass('n-tab-active');

		// add class active to this 
		this.addClass('n-tab-active');

		// show content tab 
		$('ul-content-' + rel).set('styles', {'display': 'block'});
	});
});
//-->
</script>
<?php
/**
 * @version		$Id: rentalcustomlocationid.php $
 * @copyright	Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 * @author		muinx
 * This component was generated by http://joomlavietnam.net/ - 2012
 */

defined('JPATH_BASE') or die;

jimport('joomla.html.html');
jimport('joomla.form.formfield');
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');

/**
 * Custom Field class for the Joomla Framework.
 *
 * @package		Joomla.Administrator
 * @subpackage	com_rental
 * @since		1.6
 */
class JFormFieldNeighborhoods extends JFormFieldList
{
	/**
	 * The form field type.
	 *
	 * @var		string
	 * @since	1.6
	 */
	protected $type = 'Neighborhoods';

	/**
	 * Method to get the field options.
	 *
	 * @return	array	The field option objects.
	 * @since	1.6
	 */
	public function getCategories()
	{
		// Initialize variables.
		$options = array();

		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		
		$query->select('*')
				->from('#__categories')
				->where('extension = "com_rental"')
				->where('parent_id = 1')
			;
		
		$db->setQuery($query);
		
		$categories = $db->loadObjectList();
		
		// Check for a database error.
		if ($db->getErrorNum()) {
			JError::raiseWarning(500, $db->getErrorMsg());
		}
		
		foreach ($categories as & $cate)
		{
			$query	= $db->getQuery(true);
			
			$query->select('id As value, title As text')
					->from('#__retal_location AS a')
					->where('a.state = 1')
					->where('catid = ' . (int) $cate->id . ' OR catid IN (SELECT id FROM #__categories WHERE parent_id = '. (int) $cate->id .')')
					->order('a.title');
			
			// Get the options.
			$db->setQuery($query);

			$options = $db->loadObjectList();
			
			// Check for a database error.
			if ($db->getErrorNum()) {
				JError::raiseWarning(500, $db->getErrorMsg());
			}
			
			$cate->options = $options;
		}

		return $categories;
	}
	
	public function getInput() 
	{
		if (!is_array($this->value))
			$value = unserialize($this->value);
		else
			$value = $this->value;
		
		$categories = $this->getCategories();
		
		$html = '<div id="neighborhoods_id">';
		
		$html .= '<div class="tab-container">';
		foreach ($categories as $key => $cate)
		{
			$class = ($key == 0) ? 'n-tab-active' : ''; 
			
			$html .= '<span class="n-tab '.$class.'" rel="'.$key.'">'.$cate->title.'</span>';
		}
		$html .= '</div>
					<div class="clr"></div>';
		
		foreach ($categories as $key => $cate)
		{
			$style = ($key == 0) ? '' : ' style="display: none;"';
			
			$html .= '<ul class="ul-content"'.$style.' id="ul-content-'.$key.'">';
			
			foreach ($cate->options as $option)
			{
				$checked = (is_array($value) && in_array($option->value, $value)) ? 'checked="checked"' : '';
				
				$html .= '<li><input type="checkbox"  name="'.$this->name.'[]" value="'.$option->value.'" ' . $checked . '>' . $option->text . '</li>';
			}
			
			$html .= '</ul>';
		}
		
		$html .= '</div>';
		
		return $html;
	}
}
